package com.com.collection;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class TestVector {
    public  static  void main(String []args){
        System.out.println("——————————————————————数组————————————————————————————————————");
        //数组演变历史vector(线程安全，旧)——arraylsit（线程不安全）——copyonwritearraylist（线程安全）
        //vector
        Vector<String> vector=new Vector<String>();
        vector.add("1");
        vector.add("2");
        vector.add("3");
        for (int i=0;i<vector.size();i++)
        {
            System.out.println(vector.get(i));
        }
        //arraylist
        ArrayList<String> arrayList=new ArrayList<String>();
        arrayList.add("11");
        arrayList.add("22");
        arrayList.add("33");
        for (int i=0;i<arrayList.size();i++)
        {
            System.out.println(arrayList.get(i));
        }
        //copyonwritearraylist
        CopyOnWriteArrayList<String> copyOnWriteArrayList=new CopyOnWriteArrayList<String>();
        copyOnWriteArrayList.add("111");
        copyOnWriteArrayList.add("222");
        copyOnWriteArrayList.add("333");
        for (int i=0;i<copyOnWriteArrayList.size();i++)
        {
            System.out.println(copyOnWriteArrayList.get(i));
        }
        System.out.println("————————————————————————map——————————————————————————————————");
        //map历史演变hashtable(线程安全，旧)——hashmap(线程不安全)——concurrenthashmap(线程安全)
        //hashtable
        Hashtable<String,String > hashtable=new Hashtable<String, String>();
        hashtable.put("1","xcy");
        hashtable.put("2","lj");
        for(String key:hashtable.keySet())
        {
            System.out.println(key+":"+hashtable.get(key));
        }
        //hashmap
        HashMap<String,String > hashMap=new HashMap<String, String>();
        hashMap.put("1","xjz");
        hashMap.put("2","zyl");
        for(String key:hashMap.keySet())
        {
            System.out.println(key+":"+hashMap.get(key));
        }
        //concurrenthashmap
        ConcurrentHashMap<String,String > concurrentHashMap=new ConcurrentHashMap<String, String>();
        concurrentHashMap.put("11","xjz");
        concurrentHashMap.put("22","zyl");
        for(String key:concurrentHashMap.keySet())
        {
            System.out.println(key+":"+concurrentHashMap.get(key));
        }
        System.out.println("—————————————————————————set—————————————————————————————————");
        ////hashset——treeset——linkedhashset
        //hashset
        HashSet<Integer>hashSet=new HashSet<Integer>();
        hashSet.add(5);
        hashSet.add(8);
        hashSet.add(4);
        hashSet.add(6);
        Iterator<Integer> iterator = hashSet.iterator();
        while (iterator.hasNext())
        {
            System.out.println("hashset:"+ iterator.next());
        }
        //treeset
        TreeSet<Integer>treeSet=new TreeSet<Integer>();
        treeSet.add(5);
        treeSet.add(8);
        treeSet.add(4);
        treeSet.add(6);
        Iterator<Integer> iterator2 = treeSet.iterator();
        while (iterator2.hasNext())
        {
            System.out.println("treeset:"+iterator2.next());
        }
        //linkedhashset
        LinkedHashSet<Integer>linkedHashSet=new LinkedHashSet<Integer>();
        linkedHashSet.add(5);
        linkedHashSet.add(8);
        linkedHashSet.add(4);
        linkedHashSet.add(6);
        Iterator<Integer> iterator3 = linkedHashSet.iterator();
        while (iterator3.hasNext())
        {
            System.out.println("linkedhashset:"+iterator3.next());
        }

    }
}
